#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>


#define CHANNEL_NAME 42

#define _5KB_INTEGERS (256*5)


int global_pid; 


int Run(){

	int pid = csp_pid();

	global_pid = csp_pid();

	int i=0, t;
	int *p;


	while( i < 10){
		p = (int*) malloc(_5KB_INTEGERS*sizeof(int));

		printf("Allocated 5KB (total of %i) at %pm pid=%i.\n",(i+1)*5 , p, pid);
		for(t=0; t < _5KB_INTEGERS;t++){
			p[t] = i;	
		}

		csp_yield();
		
		printf("i=%i\n", i);
		for(t=0; t < _5KB_INTEGERS;t++){
			ASSERT( p[t] == i );	
		//	if( p[t] != i ){
		//		printf("p[%i]=%i, ", t, p[t]);	
		//	}	
		}
		printf("\n");
		i++;
	}



	ASSERT( pid == csp_pid() );
	ASSERT( global_pid == csp_pid() );

	PRINTF_FOR_TESTING("%s terminating on spe #%i with pid %i\n",__FILE__ , csp_spe_id(), pid);

	PRINTF_FOR_TESTING("Nested task with pid=%i terminated with res=%i.\n", pid, res);

	return 0;
}
